using QFramework;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using UnityEngine;
using YooAsset;
public struct MyTestEvent1
{

}
public class InstantiateByAddComponent : MonoBehaviour
{

    void Start()
    {
        Debug.Log($"[InstantiateByAddComponent] 这个脚本通过AddComponent的方式实例化.");
        var package = YooAssets.GetPackage("DefaultPackage");
        AssetOperationHandle handle1 = package.LoadAssetAsync<GameObject>("Canvas");
        handle1.Completed += loadUI;

        TypeEventSystem.Global.Register<MyTestEvent1>(e =>
        {
            var package = YooAssets.GetPackage("DefaultPackage");
            AssetOperationHandle handle2 = package.LoadAssetAsync<GameObject>("MySphere");
            handle2.Completed += loadAsset;
        }).UnRegisterWhenGameObjectDestroyed(gameObject);

    }
    void loadAsset(AssetOperationHandle handle1)
    {
        GameObject go1=  handle1.InstantiateSync();
        go1.name = "HotFix-Capsule";
        //go1.AddComponent<Rigidbody>();
        // 获取Cube对象的Renderer组件
        Renderer cubeRenderer = go1.GetComponent<Renderer>();
        // 创建一个新的颜色对象，例如红色
        Color newColor = Color.red;
        // 将Cube的材质颜色设置为新的颜色
        cubeRenderer.material.color = newColor;
    }

    void loadUI(AssetOperationHandle handle1)
    {
        GameObject go1 = handle1.InstantiateSync();
    }
}
